package com.yuhs.zixing.study.design.pattern.dp001.principle.p05.open.close;

/**
 * @description 开闭原则 001
 * @author: yuhs
 * @date 2022/3/26 下午4:41
 */
public class OpenCloseDemo001 {

    public static void main(String[] args) {
        GraphicEditor001 graphicEditor = new GraphicEditor001();
        graphicEditor.drawShape(new Rectangle001());
        graphicEditor.drawShape(new Circle001());
        graphicEditor.drawShape(new Triangle001());
    }
}

/**
 * 这是一个用于绘图的类
 */
class GraphicEditor001 {

    /**
     * 接受shape 对象，然后根据type 来绘画不同图形
     */
    public void drawShape(Shape001 shape) {
        if (shape.mType == 1) {
            drawRectangle(shape);
        } else if (shape.mType == 2) {
            drawCircle(shape);
        } else if (shape.mType == 3) {
            drawTriangle(shape);
        }


    }

    public void drawRectangle(Shape001 shape) {
        System.out.println("绘制矩形");
    }

    public void drawCircle(Shape001 shape) {
        System.out.println("绘制圆形");
    }

    public void drawTriangle(Shape001 shape) {
        System.out.println("绘制三角形");
    }
}

class Shape001 {
    int mType;
}

/**
 * 矩形
 */
class Rectangle001 extends Shape001 {
    Rectangle001() {
        super.mType = 1;
    }
}

/**
 * 圆形
 */
class Circle001 extends Shape001 {
    Circle001() {
        super.mType = 2;
    }
}

/**
 * 三角形
 */
class Triangle001 extends Shape001 {
    Triangle001() {
        super.mType = 3;
    }
}
